//index.js
//获取应用实例
const app = getApp();
const Util = require('../../utils/util.js');

Page({
  data: {
    cate_id:'',
    image:''
  },
  onLoad:function(e){
    var that = this;
    var cateId = e.cate_id;
    var photoName = e.name;
    that.setData({
      cate_id: cateId,
      image: 'https://wx.himayi.cn/Public/upload/code/' + cateId + '.png',
      photoName: photoName
    });
    that.getCateDetail(cateId);        
    wx.showShareMenu({
      withShareTicket: true
    })
  },
  getCateDetail: function (cate_id) {
    var that = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        Util.getCateDetail({
          "token": res.data,
          "cate_id": cate_id
        }, function (re) {
          if (re.code == 200) {
            that.setData({
              image: re.data
            });
          }
        });
      }
    });
  },
  onShareAppMessage: function (res) {
    var cate_id = this.data.cate_id;
    var imagesData = this.data.imagesData;
    console.info(imagesData[0].thumb);
    return {
      title: 'Hi,推荐你用用这个小程序',
      path: '/pages/main/content?cate_id=' + cate_id,
      imageUrl: imagesData[0].thumb
    }
  }
})
